package com.集合.Collection___.Set_.HashSet__;

import java.util.HashSet;
import java.util.Objects;
import java.util.Set;

@SuppressWarnings("all")
public class Exercise01 {
    public static void main(String[] args) {
        /**
         *定义一个Employee类，该类包含成员属性，name，age；
         * 1.创建3个对象放入到HashSet中，
         * 2.当name和age相同时，认为时相同的元素，不会添加到HeshSet集合中；
         */
        HashSet hs = new HashSet();
        hs.add(new Employee("jeak",18));
        hs.add(new Employee("jeak",18));
        hs.add(new Employee("jeak",18));
        hs.add(new Employee("marey",18));
        hs.add(new Employee("hsp",50));
        System.out.println("hs = " + hs);
    }
}

class Employee{
    private String name;
    private int age;
    public Employee(String name, int age) {
        this.name = name;
        this.age = age;
    }

    @Override
    public boolean equals(Object o) {
       return(this.name.equals(((Employee)o).name) && this.age == ((Employee)o).age);
    }

    @Override
    public int hashCode() {
        return Objects.hash(name, age);
    }

    @Override
    public String toString() {
        return name + '\t' ;
    }
}